﻿using System.IO;
using System.Threading.Tasks;
using pandx.Mulan.Folders;

namespace pandx.Mulan.Storage;

public class FileManager : IFileManager
{
    private readonly IAppFolder _appFolder;
    private readonly ITempFileCacheManager _tempFileCacheManager;

    public FileManager(IAppFolder appFolder, ITempFileCacheManager tempFileCacheManager)
    {
        _appFolder = appFolder;
        _tempFileCacheManager = tempFileCacheManager;
    }

    public async Task SaveFile(string fileToken, string fileName)
    {
        var file = _tempFileCacheManager.GetFile(fileToken);
        await System.IO.File.WriteAllBytesAsync(
            Path.Combine(_appFolder.CommonFiesFolder, fileToken + Path.GetExtension(fileName)),
            file);
    }
}